//
//  HMVisitorViewController.swift
//  Weibo-walker
//
//  Created by 郭彬 on 16/3/3.
//  Copyright © 2016年 guobin. All rights reserved.
//

import UIKit

class HMVisitorViewController: UITableViewController {

    var userLogin: Bool = false

    override func viewDidLoad() {
        super.viewDidLoad()

    }

 

    
    override func loadView() {
        
        //将visitorView传给 VC的 View
        view = visitorView
        
        if !userLogin {
            super.loadView()
            print("已经登录成功")
        }
        setupVisitorView()
    }

    //登录不成功的按钮
    
   private func setupVisitorView(){
        
        view = visitorView
    

        // 设置右左的登录按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: "register")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: "login")
    
    }
    //懒加载这个 view
    lazy var visitorView:HMVisitorView = {
        
        let  view = HMVisitorView()
        view.registerButton.addTarget(self, action: "register", forControlEvents: .TouchUpInside)
        view.loginButton.addTarget(self, action: "login", forControlEvents: .TouchUpInside)
    
        return view
        
    }()
    
    //定义navigationItem的方法
    func login (){

        presentViewController(HMNavigationController(rootViewController: HMOAuthViewController()), animated: true) { () -> Void in
            print("跳转控制器成功")
        }
    }
  
    func register (){
        print("请注册")
        
    }
}

extension HMVisitorViewController {
    //实现协议的方法
    func visitorView(visitorView: HMVisitorView, loginButtonDidCliked: UIButton) {
        // 执行登录操作
        login()
    }

}
